#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void writeFile(const string& filename) {
    ofstream file(filename);
    if (!file.is_open()) {
        cerr << "Failed to open file for writing." << endl;
        return;
    }

    file << "Hello, World!\n";
    file << "This is a test file.\n";

    file.close();
}

void readFile(const string& filename) {
    ifstream file(filename);
    if (!file.is_open()) {
        cerr << "Failed to open file for reading." << endl;
        return;
    }

    string line;
    while (getline(file, line)) {
        cout << line << endl;
    }

    file.close();
}

int main() {
    string filename = "test.txt";

    // 写入文件
    writeFile(filename);

    // 读取文件
    readFile(filename);

    return 0;
}